<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>成功案例</title>
    <header th:replace="header::html"></header>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">成功案例</a>
            <a>
                <cite>订单完成列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row  layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form  layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="uname" placeholder="请输入雇主名字" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>

                <div class="layui-card-body ">
                    <table class="layui-hide" id="user-name-label" lay-filter="user-name-label"></table>
                </div>

                <div class="layui-card-body ">
                    <script type="text/html" id="barDemo">
                        {{# if(d.successcase == 1){     }}
                        <a class="layui-btn layui-btn-sm layui-btn-xs" lay-event="verify">设置为成功案例</a>

                        {{# }else if(d.successcase == 2){             }}
                        <a class="layui-btn layui-btn-sm layui-btn-xs" lay-event="verify">取消设置为成功案例</a>
                        {{#    }   }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
	layui.use('table', function () {
		var table = layui.table,
			form = layui.form;
		table.render({
			elem: '#user-name-label'
			, url: '/api-back/successList' //数据接口
			, page: true //开启分页
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[ //表头
                    {title:'序号',type:'numbers',width:'5%'}
					// {type: 'checkbox', fixed: 'left'},
					,{field: 'oid', title: 'ID', align: 'center',style:'display:none;'}
					, {field: 'needid', title: '需求订单',width:'13%'}
					, {field: 'workid', title: '作品订单',width:'12%'}
					, {field: 'pid', title: '订单状态',width:'12%',templet:function (st) {
						return st.pid== '4'?"已完成":"未完成"}}
					, {field: 'ostarttime', title: '开始时间',align: 'center',sort:true,width:'10%'}
					, {field: 'oendtime', title: '结束时间',width:'10%'}
					, {field: 'orealtime', title: '需求项目工期',align: 'center',width:'5%'}
					, {field: 'successcase', title: '是否设置成功案例',width:'8%',align: 'center'}
					, {title: '操作', toolbar: '#barDemo',width:'22%',align: 'center'}
				]
			]
			// done: function () {
			// 	//checkPermission();
			// }

		});
		$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头

		//监听工具条
		table.on('tool(user-name-label)', function (obj) {
			var data = obj.data;//获取点击行数据
			if(obj.event==='verify') {
				if (data.successcase == 1) {
					layer.confirm("是否设置为成功案例", function (index1) {
						$.ajax({
							url: "/api-back/updates",
							type: "GET",
							data: {oid: data.oid, successcase: data.successcase},
							dataType: 'json',
							success: function (result) {
								if (result.code == 5000111) {
									layer.alert(result.msg, {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('user-name-label');
										$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
									});

								}
							}
						});

					})
				} else {
					if (data.successcase == 2) {
						layer.confirm("是否取消成功案例", function (index2) {
							$.ajax({
								url: "/api-back/updates",
								type: "GET",
								data: {oid: data.oid, successcase: data.successcase},
								dataType: 'json',
								success: function (result) {
									if (result.code == 5000111) {
										layer.alert(result.msg, {icon: 1}, function (index2) {
											layer.close(index2);
											table.reload('user-name-label');
											$('table.layui-table thead tr th:eq(0)').addClass('layui-hide');//隐藏第一列的表头
										});

									}
								}
							});

						});
					}


				}
			}
			});
		//搜索
		form.on('submit(search)', function (data) {

		});



	 });

</script>




</body>
</html>